<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Glperiods extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model($this->session->userdata('formodel'));
		$this->load->model('wus');
		$this->load->library('upload');
		$this->load->library('variable');

	}

	public function index(){

		 $this->load->view('layouts/header',$this->variable->load_data($this->session->userdata('title')));

	    $this->load->view($this->session->userdata('formain'),array(
	    	'gps' => $this->glperiods_model->getgps()
	    	));

	    $this->load->view('layouts/footer');

	}

	public function addgp(){
		$data = array(
			':p_trx_type'	=> 'I',
			':p_bu_id'		=> $this->session->userdata('bu_id'),
			':p_fiscal_year'=> (int) $this->input->post('fiscal_year'),
			':p_period_name'=> $this->input->post('period_name'),
			':p_start_date'	=> date( "Y-m-d", strtotime($this->input->post('opened_date'))),
			':p_end_date'	=> date( "Y-m-d", strtotime($this->input->post('closed_date'))),
			':p_user_id'	=> $this->session->userdata('user_id'),
			':p_period_id'	=> '',
			':p_status'		=> ''
		);
		$this->glperiods_model->insertGP($data);
	}

	public function editgp(){
		$data = array(
			':p_trx_type'	=> 'U',
			':p_bu_id'		=> $this->session->userdata('bu_id'),
			':p_fiscal_year'=> (int) $this->input->post('fiscal_year_e'),
			':p_period_name'=> $this->input->post('period_name_e'),
			':p_start_date'	=> date( "Y-m-d", strtotime($this->input->post('opened_date_e'))),
			':p_end_date'	=> date( "Y-m-d", strtotime($this->input->post('closed_date_e'))),
			':p_status'		=> $this->input->post('status_e'),
			':p_user_id'	=> $this->session->userdata('user_id'),
			':p_period_id'	=> (int) $this->input->post('period_id_e'),
		);
		//echo json_encode($data);
		$this->glperiods_model->updateGP($data);
	}

	public function searchgp(){
		$que = $this->glperiods_model->search_gperiods($this->input->post('fiscal_year_s'),$this->input->post('period_name_s'),$this->input->post('status_s'));
		echo json_encode($que);
	}

	public function add_gperiods(){
		$this->load->view($this->session->userdata('foradd'));
	}

	public function edit_gperiods($id){
		$q = $this->glperiods_model->getgp($id);
		$this->load->view($this->session->userdata('foredit'),array(
			'edit_data' => $q
		));
	}

	public function view_gperiods($id){
		$q = $this->glperiods_model->getgp($id);
		$this->load->view($this->session->userdata('forview'),array(
			'view_data' => $q
		));
	}

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */